package Lee_code;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @author blh
 * @date 2024年08月01日 16:59
 */
public class Lee_443_81 {
    public int compress(char[] chars) {
        int len = chars.length;
        Deque<Character> charDeque = new ArrayDeque<>();
        Deque<Integer> numDeque = new ArrayDeque<>();

        for (int i = 0; i < len; i++) {
            charDeque.offer(chars[i]);
            char tempChar = chars[i];
            i++;
            int tempRepeat = 0;
            while (i < len && tempChar == chars[i]) {
                tempRepeat++;
                i++;
            }
            numDeque.offer(tempRepeat);
        }
        int res = 0;
        for (Integer i : numDeque) {
            if (i == 1) {
                res++;
            } else {
                res = res + 2;
            }
        }
        return res;
    }
}
